<template>
  <div class="view-fill">
    <div v-show="!assetDetailInfo.visible" class="app-container-flex">
      <NewFullScreen
        v-model="showDialog"
        :title="title"
        :needReturn="!flowFormType"
      >
        <template v-slot:full-button>
          <el-button
            :disabled="!canSave"
            v-if="
              !exportId &&
              $permission('assetUseExportOrder:saveAndSubmit') &&
              !flowFormType
            "
            @click="saveAndSubmit()"
            >保存并提交</el-button
          >
          <el-button v-if="!flowFormType" :disabled="!canSave" @click="save()"
            >保存</el-button
          >
        </template>
        <div class="model-panel">
          <div class="model-panel-title">
            <p>{{ $t('basic_information') }}</p>
          </div>
          <div class="model-panel-body">
            <!-- form -->
            <page-form
              class="paddingBox order-model-formBox flex_wrap_start_start"
              v-model:ref-obj="formInfo.ref"
              :disabled="formInfo.disabled"
              :data="formInfo.data"
              :field-list="formInfo.fieldList"
              :rules="formInfo.rules"
              :label-width="formInfo.labelWidth"
            >
              <template v-slot:form-contactName>
                <el-input
                  v-model="formInfo.data.contactName"
                  class="not-br not-mongolia"
                  type="input"
                  :disabled="true"
                  placeholder="请选择领用人"
                >
                  <template #append>
                    <el-icon @click="openUser"><MoreFilled /></el-icon>
                  </template>
                </el-input>
              </template>
              <template v-slot:form-depotName>
                <el-input
                  v-model="formInfo.data.depotName"
                  class="not-mongolia"
                  type="input"
                  :required="true"
                  :disabled="true"
                  placeholder="请选择出库仓库"
                >
                  <template #append>
                    <el-icon @click="selectExportDepot"><MoreFilled /></el-icon>
                  </template>
                </el-input>
              </template>
              <template v-slot:form-useDeptName>
                <el-input
                  v-model="formInfo.data.useDeptName"
                  class="not-mongolia"
                  type="input"
                  :disabled="true"
                  placeholder="请选择领用部门"
                >
                  <template #append>
                    <el-icon @click="selectDept"><MoreFilled /></el-icon>
                  </template>
                </el-input>
              </template>
            </page-form>
          </div>
        </div>

        <div class="model-panel">
          <div class="model-panel-title">
            <Tooltip :text="$t('detailInfo')"></Tooltip>
          </div>
          <div class="model-panel-body">
            <!-- 条件栏 -->
            <page-filter :filter-list="filterInfo.list">
              <template v-slot:filter-addProduct>
                <el-button :disabled="!canAddProduct" @click="addProduct"
                  >添加资产</el-button
                >
              </template>
              <template v-slot:filter-removeProduct>
                <el-button
                  :disabled="!canRemoveProduct"
                  @click="removeProduct()"
                  >删除资产</el-button
                >
              </template>
              <template v-slot:filter-batchDept>
                <el-button :disabled="!canBatchDept" @click="batchDept()"
                  >批量设置使用部门</el-button
                >
              </template>
              <template v-slot:filter-assetCodeScan>
                <ScanInputBox
                  :query="scanInfo.query"
                  :disabled="!formInfo.data.depotId"
                  @callback="onCallBackScanData"
                />
              </template>
            </page-filter>
            <div class="flex_full_item">
              <el-form ref="tableForm" :model="tableInfo" style="width: 100%">
                <!-- 表格 -->
                <page-table
                  :refresh="tableInfo.refresh"
                  :init-curpage="tableInfo.initCurpage"
                  v-model:data="tableInfo.data"
                  :pager="false"
                  :summary="true"
                  :summary-field-list="tableInfo.summaryFieldList"
                  :tab-index="true"
                  :field-list="tableInfo.fieldList"
                  :handle="tableInfo.handle"
                  :row-class-name="tableRowClassName"
                  :isDynamic="true"
                  @handleEvent="handleEvent"
                >
                  <template v-slot:col-assetUseDeptValue="scope">
                    <template
                      v-if="
                        scope.row.assetUseDeptBusinessList &&
                        scope.row.assetUseDeptBusinessList.length
                      "
                    >
                      <span
                        v-for="(item, index) in scope.row
                          .assetUseDeptBusinessList"
                        :key="index"
                      >
                        {{ item.useDeptName }}-{{ item.rate }}
                        <span
                          v-show="
                            index <
                            scope.row.assetUseDeptBusinessList.length - 1
                          "
                          >,</span
                        >
                      </span>
                    </template>
                    <template v-else>
                      <span> - </span>
                    </template>
                  </template>
                  <template v-slot:col-assetName="scope">
                    <span
                      class="slip-edit"
                      @click="showAssetDetail(scope.row)"
                      >{{ scope.row.assetName }}</span
                    >
                  </template>
                </page-table>
              </el-form>
            </div>
          </div>
        </div>
      </NewFullScreen>
    </div>
    <SelectDepot
      v-if="selectDepotInfo.visible"
      v-model:show-dialog="selectDepotInfo.visible"
      :check-box="false"
      :query="selectDepotInfo.query"
      :highlight-row="true"
      :check-lock="true"
      :save-empty="true"
      @callback="selectDepotCallBack"
    />
    <!-- 选择部门 -->
    <SelectDept
      v-if="deptInfo.visible"
      v-model:show-dialog="deptInfo.visible"
      :query="deptInfo.query"
      :check-box="false"
      :highlight-row="true"
      :save-empty="true"
      @callback="selectDeptCallback"
    />
    <!--资产选择-->
    <Select-asset
      v-if="selectAssetInfo.visible"
      v-model:show-dialog="selectAssetInfo.visible"
      :highlight-row="false"
      :check-box="true"
      :table-key="selectAssetInfo.tableKey"
      :query="selectAssetInfo.query.queryMap"
      :query-params="selectAssetInfo.query.queryParams"
      @callback="callBackAsset"
    />
    <Amortization
      v-if="addAmortizationInfo.visible"
      v-model:show-dialog="addAmortizationInfo.visible"
      :list="addAmortizationInfo.row.assetUseDeptBusinessList"
      @callback="amortizationBack"
    ></Amortization>
    <!-- 详情页 -->
    <asset-card-detail
      v-if="assetDetailInfo.visible"
      :id="assetDetailInfo.id"
      v-model:visible="assetDetailInfo.visible"
      :title="assetDetailInfo.title"
    />
    <SelectUsers
      v-if="selectUserInfo.visible"
      v-model:show-dialog="selectUserInfo.visible"
      :query="selectUserInfo.query"
      :check-box="false"
      :highlight-row="true"
      :api="getOrganizationPage"
      :save-empty="true"
      @callback="selectUserInfoBack"
    />
  </div>
</template>

<script setup name="AssetUseExportOrderModify">
import {
  createAssetUseExportOrder,
  createAssetUseExportOrderAndSave,
  submitAssetUseExportOrder,
  detailAssetUseExportOrder,
  updateAssetUseExportOrder,
  flushOrderDetail,
  assetUseExportOrderDetailsCustomizeListAll,
  selectBuildCard,
} from '@/api/asset'
import ScanInputBox from '@/components/SelectAsset/ScanInputBox'
import { getOrganizationPage } from '@/api/base'
import { getCustomizeSetting } from '@/api/customize'
import { getCurrentFiscalPeriod } from '@/api/core.js'
import moment from 'moment'
const AssetCardDetail = defineAsyncComponent(() =>
  import('@/views/asset/assetManage/assetCard/details')
)

const { proxy } = getCurrentInstance()
const emits = defineEmits()
const props = defineProps([
  'visible',
  'title',
  'exportId',
  'flowFormType',
  'id',
  'otherFormData',
])

const systemConfig = ref(proxy.$store.state.permission.systemConfig)
const scanInfo = ref({
  query: {
    depotId: '',
    assetSourceAuth: true,
  },
})
//表单相关
const formInfo = ref({
  ref: null,
  data: {
    depotName: '',
    depotId: '',
    deptName: '',
    useDeptName: proxy.$store.state.user.userInfo.dept
      ? proxy.$store.state.user.userInfo.dept.name
      : '',
    useDeptId: proxy.$store.state.user.userInfo.dept
      ? proxy.$store.state.user.userInfo.dept.id
      : '',
    deptId: '',
    phone: '',
  },
  fieldList: [
    {
      label: '出库仓库',
      value: 'depotName',
      type: 'slot',
      require: true,
    },
    {
      label: '出库部门',
      value: 'deptName',
      type: 'input',
      disabled: true,
      show: false,
    },
    {
      label: '领用部门',
      value: 'useDeptName',
      type: 'slot',
    },
    {
      label: '领用人',
      value: 'contactName',
      type: 'slot',
    },
    { label: '领用人电话', value: 'phone', type: 'input', maxlength: 15 },
    {
      label: '业务日期',
      value: 'businessDate',
      type: 'date',
      labelTip: '',
      TimePickerOptions: {},
    },
    {
      label: '备注',
      value: 'remark',
      type: 'textarea',
      maxlength: 200,
    },
  ],
  rules: {
    depotName: [
      { required: true, message: '请选择出库仓库', trigger: 'change' },
    ],
    useDeptName: [
      { required: true, message: '请选择领用部门', trigger: 'change' },
    ],
    phone: [{ validator: proxy.$validate.cellphone, trigger: 'blur' }],
    businessDate: [
      { required: true, message: '请选择业务日期', target: 'blur' },
    ],
  },
  labelWidth: '120px',
})
// 过滤相关配置
const filterInfo = ref({
  query: {
    customizeUserVO: {},
    queryMap: {
      orderId: {
        queryType: 'EQUALS',
        queryCategory: 'AND',
        value: null,
      },
    },
    queryParams: {},
  },
  list: [
    { type: 'slot', value: 'addProduct' },
    { type: 'slot', value: 'removeProduct' },
    { type: 'slot', value: 'batchDept' },
    { type: 'slot', value: 'assetCodeScan' },
  ],
})
const deptInfo = ref({
  visible: false,
  query: {
    deptAuth: 'id',
    status: '1',
  },
})
// 表格相关
const tableInfo = ref({
  refresh: 1,
  initCurpage: 1,
  data: [],
  selections: [],
  fieldList: [],
  handle: {
    fixed: 'right',
    label: '操作',
    width: '150',
    btList: [
      {
        label: '添加使用部门',
        event: addAmortization,
        show: true,
      },
      {
        label: '删除',
        event: removeProduct,
        popconfirmText: '删除后将改变数据,是否继续？',
        show: true,
      },
    ],
  },
})
const selectUserInfo = ref({
  visible: false,
  query: {
    status: 1,
    idNotIn: '',
  },
})
const selectDepotInfo = ref({
  visible: false,
  query: {
    depotAuth: 'id',
    status: 1,
    useTypeId: 2,
  },
})
const selectAssetInfo = ref({
  visible: false,
  tableKey:
    'assetUseExportOrderAddAsset-com.slip.spd.entity.vo.core.CoreAssetVO',
  query: {
    queryMap: {
      id: {
        queryType: 'NOT_IN',
        queryCategory: 'AND',
        value: '',
      },
      depotId: {
        queryType: 'EQUALS',
        queryCategory: 'AND',
        value: '',
      },
      assetStatus: {
        queryType: 'EQUALS',
        queryCategory: 'AND',
        value: 3,
      },
      status: {
        queryType: 'IN',
        queryCategory: 'AND',
        value: '3',
      },
      useStatus: {
        queryType: 'EQUALS',
        queryCategory: 'AND',
        value: 1,
      },
      isLocked: {
        queryType: 'EQUALS',
        queryCategory: 'AND',
        value: 0,
      },
    },
    queryParams: {},
  },
})
const addAmortizationInfo = ref({
  row: {},
  visible: false,
})
const assetDetailInfo = ref({
  visible: false,
  id: '',
  title: '资产详情',
})
const changeAmortizationDeptNameFlag = ref(false)
const formRefs = ref([])

const showDialog = computed({
  get() {
    return props.visible
  },
  set(newValue) {
    emits('update:visible', newValue) // 更新父组件visible
  },
})
const canSave = computed(() => {
  return tableInfo.value.data.length
})
const canAddProduct = computed(() => {
  return formInfo.value.data.depotId && formInfo.value.data.deptId
})
const canRemoveProduct = computed(() => {
  return tableInfo.value.selections.length
})
const canBatchDept = computed(() => {
  return tableInfo.value.selections.length
})
onMounted(() => {
  proxy.$nextTick(() => {
    formRefs.value = [proxy.$refs['tableForm'], formInfo.value.ref]
  })
  setData()
  if (props.otherFormData) {
    setFormData(props.otherFormData)
  }
})

function setData() {
  // 设置自定义表格
  let obj = {
    assetUseDeptValue: {
      label: '使用部门',
      value: 'assetUseDeptValue',
      componentType: 'input',
      type: 'slot',
      show: false,
      hidden: true,
    },
  }
  tableInfo.value.fieldList = Object.values({
    ...proxy.$fn.deepClone(proxy.$fieldfList.FieldList),
    ...obj,
  })
  getCustomize()
  getFiscalPeriod()
}
function setFormData(data) {
  formInfo.value.data.depotId = data.depotId
  formInfo.value.data.depotName = data.depotName
  formInfo.value.data.deptName = data.deptName
  formInfo.value.data.deptId = data.deptId
  scanInfo.value.query['depotId'] = data.depotId
  selectBuildCard(data.ids).then((resp) => {
    if (resp && resp.success && resp.data.length) {
      resp.data.forEach((item) => {
        item['assetId'] = item.id
        item['price'] = item.primitiveOriginalAmount
        if (formInfo.value.data.useDeptName) {
          item['assetUseDeptBusinessList'] = [
            {
              useDeptName: formInfo.value.data.useDeptName,
              useDeptId: formInfo.value.data.useDeptId,
              rate: 100,
              assetId: item.assetId,
            },
          ]
        }
        item['originalUseDeptList'] = item.assetUseDeptVOList || []
      })
      tableInfo.value.data = resp.data
    }
  })
}
function openUser() {
  selectUserInfo.value.visible = true
  selectUserInfo.value.query.idNotIn = formInfo.value.data.contact
}
function selectUserInfoBack(data) {
  if (data && data.id) {
    formInfo.value.data.contactName = data.name
    formInfo.value.data.contact = data.id
    formInfo.value.data.phone = data.tel || ''
  } else {
    formInfo.value.data.contactName = ''
    formInfo.value.data.contact = ''
    formInfo.value.data.phone = ''
  }
}
function batchDept() {
  //批量设置使用部门
  addAmortizationInfo.value.visible = true
  addAmortizationInfo.value.type = 'batch'
  addAmortizationInfo.value.row = {}
  addAmortizationInfo.value.row.assetUseDeptBusinessList = [
    {
      useDeptName: formInfo.value.data.useDeptName,
      useDeptId: formInfo.value.data.useDeptId,
      rate: 100,
    },
  ]
}

//添加使用部门比率
function addAmortization(row) {
  if (
    !changeAmortizationDeptNameFlag.value &&
    formInfo.value.data.useDeptName
  ) {
    row.assetUseDeptBusinessList = [
      {
        useDeptName: formInfo.value.data.useDeptName,
        useDeptId: formInfo.value.data.useDeptId,
        rate: 100,
      },
    ]
  }
  addAmortizationInfo.value.row = row
  addAmortizationInfo.value.visible = true
  addAmortizationInfo.value.type = 'one'
}
function amortizationBack(row, _changeAmortizationDeptNameFlag) {
  console.log(row)
  if (addAmortizationInfo.value.type === 'one') {
    changeAmortizationDeptNameFlag.value = _changeAmortizationDeptNameFlag
    if (row && row.length) {
      row.forEach((item) => {
        item['assetId'] = addAmortizationInfo.value.row.assetId
      })
    }
    let assetCode = addAmortizationInfo.value.row.assetCode
    let index = tableInfo.value.data.findIndex(
      (item) => item.assetCode === assetCode
    )
    if (index > -1) {
      tableInfo.value.data[index]['assetUseDeptBusinessList'] = row
    }
  } else {
    //批量
    changeAmortizationDeptNameFlag.value = _changeAmortizationDeptNameFlag
    if (row && row.length) {
      tableInfo.value.selections.forEach((item) => {
        item['assetUseDeptBusinessList'] = row
      })
    }
  }
}
function selectDept() {
  deptInfo.value.visible = true
  deptInfo.value.query.idNotIn = formInfo.value.data.useDeptId
}
function selectDeptCallback(row) {
  if (tableInfo.value.data.length) {
    let list = tableInfo.value.data.filter(
      (item) =>
        item.assetUseDeptBusinessList && item.assetUseDeptBusinessList.length
    )
    if (list.length > 0) {
      proxy
        .$confirm(
          '更改使用部门将覆盖明细列表使用部门-比例，确定更改?',
          '提示',
          {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning',
          }
        )
        .then(() => {
          if (row && row.id) {
            formInfo.value.data.useDeptName = row.name
            formInfo.value.data.useDeptId = row.id
          } else {
            formInfo.value.data.useDeptName = ''
            formInfo.value.data.useDeptId = ''
          }
          tableInfo.value.data.forEach((item) => {
            item.assetUseDeptBusinessList = [
              {
                useDeptName: formInfo.value.data.useDeptName,
                useDeptId: formInfo.value.data.useDeptId,
                rate: 100,
              },
            ]
          })
        })
    } else {
      if (row && row.id) {
        formInfo.value.data.useDeptName = row.name
        formInfo.value.data.useDeptId = row.id
      } else {
        formInfo.value.data.useDeptName = ''
        formInfo.value.data.useDeptId = ''
      }
      tableInfo.value.data.forEach((item) => {
        item.assetUseDeptBusinessList = [
          {
            useDeptName: formInfo.value.data.useDeptName,
            useDeptId: formInfo.value.data.useDeptId,
            rate: 100,
          },
        ]
      })
    }
  } else {
    if (row && row.id) {
      formInfo.value.data.useDeptName = row.name
      formInfo.value.data.useDeptId = row.id
    } else {
      formInfo.value.data.useDeptName = ''
      formInfo.value.data.useDeptId = ''
    }
  }
}
function largeMax(row) {
  if (row.qtyOperateMode === 2) {
    return parseInt(row.stockAvailableCalcQty / row.unitConvertCoefficient)
  } else {
    return row.stockAvailableQty
  }
}
function smallMax(row) {
  let largeUnitQty = parseInt(
    row.stockAvailableCalcQty / row.unitConvertCoefficient
  )
  if (largeUnitQty === 0 || row.largeUnitQty === largeUnitQty) {
    return parseInt(row.stockAvailableCalcQty % row.unitConvertCoefficient)
  } else {
    return row.unitConvertCoefficient - 1
  }
}
function changeLarge(e, row, str) {
  proxy.$refs.tableForm.clearValidate(str)
  let largeUnitQty = parseInt(
    row.stockAvailableCalcQty / row.unitConvertCoefficient
  )
  if (row.qtyOperateMode === 2 && row.unitConvertCoefficient > 1) {
    if (largeUnitQty > 0 && e === largeUnitQty) {
      let smallUnitQty = parseInt(
        row.stockAvailableCalcQty % row.unitConvertCoefficient
      )
      if (row.smallUnitQty > smallUnitQty) {
        row.smallUnitQty = smallUnitQty
      }
    }
  }
}
function tableRowClassName({ row = undefined }) {
  if (row.isChoice) {
    return 'success-row'
  } else {
    return ''
  }
}
function getMain() {
  detailAssetUseExportOrder(props.id || props.exportId).then((resp) => {
    if (resp && resp.success) {
      formInfo.value.data = resp.data
      scanInfo.value.query['depotId'] = formInfo.value.data.depotId
    }
  })
  filterInfo.value.query.queryMap.orderId.value = props.id || props.exportId
  getList()
}
function getList() {
  //修改请求明细信息
  assetUseExportOrderDetailsCustomizeListAll(filterInfo.value.query).then(
    (resp) => {
      if (resp && resp.success && resp.data.length) {
        let data = resp.data
        tableInfo.value.data = data
      }
    }
  )
}
// 触发事件
function handleEvent(event, data) {
  switch (event) {
    case 'tableCheck':
      tableInfo.value.selections = [...data]
      break
  }
}
// flowData 外部流程页面调用
function saveAndSubmit(flowData) {
  save(true, flowData)
}
function save(isSaveAndSubmit, obj = {}) {
  formRefs.value = [proxy.$refs['tableForm'], formInfo.value.ref]
  proxy.$fn.checkForm(formRefs.value).then(() => {
    const data = formInfo.value.data
    let arr = []
    tableInfo.value.data.forEach((item) => {
      if (
        !item.assetUseDeptBusinessList ||
        !item.assetUseDeptBusinessList.length
      ) {
        arr.push(item.assetName + '-' + item.assetCode)
      }
    })
    if (arr.length) {
      proxy.$message({
        showClose: true,
        message: `请添加资产【${arr}】使用部门占比`,
        type: 'warning',
        duration: 3500,
      })
      return
    }
    data.mergeDetails = tableInfo.value.data
    let api = data.id
      ? updateAssetUseExportOrder
      : isSaveAndSubmit === true
      ? createAssetUseExportOrderAndSave
      : createAssetUseExportOrder
    let flowParams = data
    if (isSaveAndSubmit) {
      if (proxy.$route.query.processInstanceId) {
        api = submitAssetUseExportOrder
      }
      flowParams = {
        orderData: data,
        // flowTaskCommentDto和processDefinitionKey为审批流程需要传递的参数
        flowTaskCommentDto: { approvalType: 'submit' },
        processDefinitionKey: 'assetUseExport',
        processInstanceId: obj.processInstanceId,
        taskId: obj.taskId,
      }
    }
    api(flowParams).then((resp) => {
      if (resp && resp.success) {
        if (resp.msgType === 'messageBox' && data.id) {
          flushOrderDetail([data.id]).then()
        }
        if (props.otherFormData) {
          let data = {
            urlType: 1,
            url: '/asset/assetManage/assetUseExport',
          }
          proxy.$router.push('/asset/assetManage/assetUseExport')
          proxy.$store.dispatch('settings/toPage', data)
          showDialog.value = false
          return
        }
        showDialog.value = false
        emits('returnModify')
      }
    })
  })
}
//选择出库仓库
function selectExportDepot() {
  selectDepotInfo.value.visible = true
  selectDepotInfo.value.query.idNot = formInfo.value.data.depotId
}
function selectDepotCallBack(data = undefined) {
  if (data && data.id) {
    formInfo.value.data.depotId = data.id
    formInfo.value.data.depotName = data.name
    formInfo.value.data.deptName = data.deptName || ''
    formInfo.value.data.deptId = data.deptId || ''
    scanInfo.value.query['depotId'] = data.id
    tableInfo.value.data = []
  } else {
    formInfo.value.data.depotId = ''
    formInfo.value.data.depotName = ''
    formInfo.value.data.deptName = ''
    formInfo.value.data.deptId = ''
    scanInfo.value.query['depotId'] = ''
    tableInfo.value.data = []
  }
}
//选择库存产品
function addProduct() {
  let ids = tableInfo.value.data.map((item) => item.assetId)
  selectAssetInfo.value.query.queryMap.id.value = ids.length
    ? ids.toString()
    : ''
  selectAssetInfo.value.query.queryMap.depotId.value =
    formInfo.value.data.depotId
  selectAssetInfo.value.visible = true
}
function callBackAsset(data) {
  if (data.length) {
    data.forEach((item) => {
      item['assetId'] = item.id
      item['price'] = item.primitiveOriginalAmount
      if (formInfo.value.data.useDeptName) {
        item['assetUseDeptBusinessList'] = [
          {
            useDeptName: formInfo.value.data.useDeptName,
            useDeptId: formInfo.value.data.useDeptId,
            rate: 100,
            assetId: item.assetId,
          },
        ]
      }
      item['originalUseDeptList'] = item.assetUseDeptVOList || []
    })
  }
  tableInfo.value.data = data.concat(tableInfo.value.data)
}
function onCallBackScanData(data, callback) {
  if (data && data.assetCode) {
    data.assetId = data.id
    if (formInfo.value.data.useDeptName) {
      data['assetUseDeptBusinessList'] = [
        {
          useDeptName: formInfo.value.data.useDeptName,
          useDeptId: formInfo.value.data.useDeptId,
          rate: 100,
        },
      ]
    } else {
      data['assetUseDeptBusinessList'] = []
    }
    data['originalUseDeptList'] = data.assetUseDeptVOList || []
    if (tableInfo.value.data) {
      tableInfo.value.data.forEach((item) => {
        item.isChoice = false
      })
      let index = tableInfo.value.data.findIndex(
        (item) => item.assetCode === data.assetCode
      )
      if (index !== -1) {
        callback(true)
      } else {
        tableInfo.value.data.unshift(data)
        callback(false)
      }
    } else {
      tableInfo.value.data.unshift(data)
      callback(true)
    }
  }
}
//删除产品
function removeProduct(row = undefined) {
  if (row && row.id) {
    tableInfo.value.data = tableInfo.value.data.filter((item) => item !== row)
  } else {
    proxy
      .$confirm('删除后将改变数据,是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
      .then(() => {
        tableInfo.value.data = tableInfo.value.data.filter((row) => {
          return !tableInfo.value.selections.includes(row)
        })
      })
  }
}
function getFiscalPeriod() {
  getCurrentFiscalPeriod(2).then((res) => {
    if (res && res.success) {
      let index = formInfo.value.fieldList.findIndex(
        (item) => item.value === 'businessDate'
      )
      let fiscalPeriodName = res.data.name
      if (index > -1) {
        formInfo.value.fieldList[
          index
        ].labelTip = `当前会计期间：${fiscalPeriodName}`
        formInfo.value.fieldList[index].TimePickerOptions = {
          disabledDate(time) {
            return (
              time.getTime() <
              new Date(res.data.startDate).getTime() - 24 * 60 * 60 * 1000
            )
          },
        }
      }
    }
  })
}
function getCustomize() {
  let param = {
    tableKey:
      'assetUseExportOrderModify-com.slip.spd.entity.vo.asset.AssetUseExportOrderDetailVO',
  }
  getCustomizeSetting(param).then((res) => {
    if (res && res.success) {
      let data = res.data
      tableInfo.value.fieldList = proxy.$fn.setFieldList(
        tableInfo.value.fieldList,
        data.detail
      )
      filterInfo.value.query.customizeUserVO = data
      if (props.id || props.exportId) {
        getMain()
      }
    }
  })
}
function showAssetDetail(row) {
  assetDetailInfo.value.id = row.assetId
  assetDetailInfo.value.visible = true
}
// 名称不要做改变，在流程引擎中需要通过refs进行调用
defineExpose({
  save,
  saveAndSubmit,
})
</script>

<style scoped lang="scss">
:deep(.page-table) > .el-table {
  overflow: hidden;
}
</style>
